using System;
using System.Windows;

using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;

using ApplicationHost.Views;
using Microsoft.Practices.Prism.Regions;
using Infrastructure.Adapters;
using Infrastructure;
using Telerik.Windows.Controls;

namespace ApplicationHost
{
    public partial class Bootstrapper : UnityBootstrapper
    {
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            // Create the module catalog from a XAML file.
            var uri = new Uri("/ApplicationHost;component/ModuleCatalog.xaml", UriKind.Relative);
            var catalog = Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(uri);
            return catalog;
        }

        protected override DependencyObject CreateShell()
        {
            // Use the container to create an instance of the shell.
            IRegionManager manager = this.Container.TryResolve<IRegionManager>();
            ShellView view = Container.TryResolve<ShellView>();
            //manager.RegisterViewWithRegion(RegionNames.HostRegion, () => this.Container.TryResolve<DockView>());

            view.Dispatcher.BeginInvoke((Action)delegate
            {
                // Display the shell's root visual.
                view.Show();
                view.Activate();
                
                //Close the splash screen
                DevExpress.Xpf.Core.DXSplashScreen.Close();
            });
            return view;
        }

        protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
        {
            RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
            mappings.RegisterMapping(typeof(RadOutlookBar), Container.TryResolve<RadOutlookBarRegionAdapter>());
            return mappings;
        }
    }
}